import { setToken, getToken } from '@/utils/auth'
import { login, sysProfile, sysUser } from '@/api/user.js'
const state = {
  token: getToken() || '',
  userInfo: ''
}
const mutations = {
  setToken(state, value) {
    state.token = value
    setToken(value)
  },
  setUserInfo(state, value) {
    state.userInfo = value
  },
  logout(state) {
    state.token = ''
    setToken('')
    state.userInfo = ''
  }
}
const actions = {
  async toLogin(store, value) {
    const res = await login(value)
    store.commit('setToken', res.data)
  },
  async getUserInfo({ commit }) {
    const res = await sysProfile()
    const res2 = await sysUser(res.data.userId)
    commit('setUserInfo', { ...res.data, ...res2.data })
    console.log(res, res2)
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
